package com.lihepeng.leecode.array2;

/**
 * solution 303
 * 数组不可变  计算一定索引之内的元素之和
 */
public class NumArray {
    int []preNumArray;
    public NumArray(int[] nums) {
        preNumArray = new int[nums.length+1];
        preNumArray[0]=0;
        for (int i =0;i<nums.length;i++) {
            preNumArray[i+1]=nums[i]+nums[i];
        }

    }

    public int sumRange(int left, int right) {
        return preNumArray[right+1] - preNumArray[left];
    }
}
